<template>
  <div style="margin:20px;padding-top:50px">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card" style="height:475px">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group">
              <li class="list-group-item">
                <div><i class="el-icon-user-solid" />用户名称</div>
                <div class="pull-right">{{ user.user_name }}</div>
              </li>
              <li class="list-group-item">
                <div><i class="el-icon-phone" />手机号码</div>
                <div class="pull-right">{{ user.phone }}</div>
              </li>
              <li class="list-group-item">
                <div><i class="el-icon-s-comment" />用户邮箱</div>
                <div class="pull-right">{{ user.email }}</div>
              </li>
              <li class="list-group-item">
                <div><i class="el-icon-s-platform" />所属部门</div>
                <div> {{ deptName }}</div>
              </li>
              <li class="list-group-item">
                <div><i class="el-icon-s-check" />所属角色</div>
                <div class="pull-right">{{ role }}</div>
              </li>
              <li class="list-group-item">
                <div><i class="el-icon-date" />创建日期</div>
                <div class="pull-right">{{ dateFormat1('yyyy-mm-dd HH:MM:SS',user.created_at )}}
                </div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card style="height:475px">
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd :user="user" />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
// import { getUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd },
  data() {
    return {
      user: {},
      activeTab: "userinfo",
      role: "",
      deptName: ""
    };
  },
  created() {
    let a = [];
    this.user = this.$store.getters.userInfo.user;
    if (this.user.is_admin) {
      this.role = "超级管理员";
    } else {
      this.user.role.forEach(item => {
        a.push(item.role_name);
        this.role = a.join(",");
      });
    }
    if (this.user.department) {
      this.deptName = this.user.department.department_name;
    }
  },

  computed: {},
  methods: {}
};
</script>
<style scoped>
.text-align {
  text-align: center;
}

.list-group {
  padding-left: 0;
  list-style: none;
}
.list-group-item {
  border-radius: 0;
  border-bottom: 1px solid #e7eaec;
  border-top: 1px solid #e7eaec;
  margin-bottom: -1px;
  padding: 11px 0;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}
</style>
